<template>
  <div class="header">
    <span @click="changeMenu">
      <i
        class="iconfont"
        :class="flag ? 'icon-left-indent' : 'icon-right-indent'"
      ></i>
    </span>
    <div class="header-right">
      <el-dropdown trigger="click" @command="dropDown">
        <span class="el-dropdown-link">
          {{ $t("home.lang") }}
          <i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="zh">
            {{ $t("home.Chinese") }}
          </el-dropdown-item>
          <el-dropdown-item command="en">
            {{ $t("home.English") }}
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <span>欢迎：{{ userInfo.user }}</span>
      <span @click="exit"><i class="iconfont icon-tuichu"></i></span>
    </div>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
export default {
  name: "HeaderNav",
  data() {
    return {
      flag: false,
    };
  },
  computed: {
    ...mapState("loginModule", ["userInfo"]),
  },
  methods: {
    ...mapMutations("loginModule", ["setUser"]),
    changeMenu() {
      this.flag = !this.flag;
      this.$emit("transMenu", this.flag);
    },
    exit() {
      //退出并清空缓存
      // console.log("退出并清空缓存");
      this.setUser({
        user: "",
        token: "",
        isLogin: false,
      });
      localStorage.removeItem("userToken");
      this.$router.push("/login");
    },
    /**
     * 切换语言
     */
    dropDown(command) {
      // console.log("123", command);
      this.$i18n.locale = command;
      // console.log(this);
    },
  },
};
</script>

<style lang="less" scoped>
.header {
  height: 50px;
  line-height: 50px;
  background: #1e78bf;
  // color: #fff;
  font-size: 14px;
  .iconfont {
    font-size: 20px;
  }
  .header-right {
    float: right;
    height: 100%;
    span {
      margin: 0 5px;
      color: #fff;
      .iconfont {
        position: relative;
        top: 2px;
      }
    }
  }
}
</style>